package com.yanqu.road.server.cmd.zhaoshang;

import com.yanqu.road.entity.zhaoshang.ZsWarReport;
import com.yanqu.road.entity.zhaoshang.enums.eZsReportType;
import com.yanqu.road.logic.pb.ZhaoShangPb;
import com.yanqu.road.pb.zhaoshang.ZhaoShangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.zhaoshang.ZsModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.*;

@Cmd(code = Protocol.S_ZS_WAR_REPORT_LIST, desc = "战报列表")
public class ZsWarReportListCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {

        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        List<ZsWarReport> allList = new ArrayList<>();
        Map<Long, List<ZsWarReport>> map = player.getModule(ZsModule.class).getWarReportMap();
        for(long key : map.keySet()){
            List<ZsWarReport> temp = map.get(key);
            int size = temp.size();
            for(int i = 0; i < size; i++){
                if(temp.get(i).getType() != eZsReportType.Complete.getIntValue()) {   //收官不展示
                    allList.add(temp.get(i));
                }
            }
        }
        ZhaoShangProto.ZsWarReportListRespMsg.Builder respMsg = ZhaoShangProto.ZsWarReportListRespMsg.newBuilder();
        respMsg.setRet(ret);
        for(ZsWarReport report : allList){
            respMsg.addReportList(ZhaoShangPb.parseToZsWarReportTemp(report));
        }
        player.sendPacket(Protocol.U_ZS_WAR_REPORT_LIST, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
